package com.onec.service.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class PrintQueue {

    private Lock queueLock;


    public PrintQueue(boolean fireMode) {
        this.queueLock = new ReentrantLock(fireMode);
    }

    public void printJob(Object document) {

        queueLock.lock();

        long duration = (long) (Math.random() * 1000);

        System.out.println("-->" + Thread.currentThread().getName() + "sleep --->" + duration / 1000 + "seconds");
        try {
            Thread.sleep(duration);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            queueLock.unlock();
        }

    }


}
